package com.jxz.vip.function.impl;

import com.jxz.common.ThisSystemException;
import com.jxz.vip.dao.UserDao;
import com.jxz.vip.entity.UserEntity;
import com.jxz.vip.function.UserFunction;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import static com.jxz.common.ThisSystemUtil.*;

/**
 * Created by 金贤哲 on 2017/3/29 0029.
 */
@Service
public class UserFunctionImpl implements UserFunction{
    @Autowired
    UserDao udao;
    @Override
    public UserEntity login(String account, String password) throws Exception {
        account = $("账户不能为空",account);
        password = $("密码不能为空",password);
        UserEntity u = udao.selectByAccount(account);
        if(u == null){
            throw new ThisSystemException("账户不存在");
        }
        if(!u.getPassword().equals(password)){
            throw new ThisSystemException("密码错误");
        }
        return u;
    }
}
